import {TPopupMenu, TToolMenuButton} from "../../../hcl/StdCtrls.js";
import {TAlign, THorizontalAlign} from "../../../hcl/Controls.js";
import {theme} from "../../../hcl/theme.js";
import {TRect} from "../../../hcl/System.js";

export class EmrToolMenuButton extends TToolMenuButton {
    constructor(text, imgSrc, itemArray) {
        super(text);
        this.image.src = imgSrc;
        this.textVisible = true;
        this.align = TAlign.Left;
        this.image.align = THorizontalAlign.Center;


        let menuFile = new TPopupMenu();
        menuFile.dropDownStyle = true;
        if (itemArray) {
            for (let i = 0; i < itemArray.length; i++) {
                menuFile.addItem(itemArray[i]);
            }
        }
        this.dropDownMenu = menuFile;

    }

    doPaintText_(hclCanvas, x, y) {
        hclCanvas.font.assign(this.font);
        if (!this.enabled)
            hclCanvas.font.color = theme.textDisableColor;
        var vY = y + this.image.height;
        hclCanvas.textOut(x - this.image.width / 2 + theme.dropDownButtonSize / 4, vY, this.text_);
    }

    doImageLoaded_() {
        this.paddingLeft = theme.iconWidth;
        this.doSetAutoWidth_();
        this.image.left = Math.max(0, (this.width - this.image.width - theme.dropDownButtonSize) / 2);
        var tRect = this.image.bounds();
        this.updateRect(tRect);
    }

    doPaintBackground_(hclCanvas) {
        //    super.doPaintBackground_(hclCanvas);
        var left = Math.max(0, (this.width - this.image.width - theme.dropDownButtonSize) / 2);
        theme.drawDropDown(hclCanvas, TRect.CreateByBounds(left + theme.dropDownButtonSize,
            0, theme.dropDownButtonSize, this.height));
    }

    //鼠标移入事件
    doMouseMove_(e) {
        return;
    }

    doMouseEnter_() {
        return;
    }
}